var e = require;
var t = module;
var o = exports;
var n = o;
Object.defineProperty(n, "__esModule", {value: !0}), (n.nowScoreModel = void 0);
var i = e("GlobalParam"),
    a = e("Util"),
    r = e("GameData"),
    s = e("PlayerLevel"),
    c = function () {
        (this.oldScore = 0), (this.killNum = 0), (this.killScore = 0), (this.level_addScore = 1);
    };
n.nowScoreModel = c;
var l = (function () {
    function e() {
        (this.nowScoreList = []), (this.gameDatalist = []);
    }
    return (
        Object.defineProperty(e, "instance", {
            get: function () {
                return e._instance || (e._instance = new e()), e._instance;
            },
            enumerable: !1,
            configurable: !0
        }),
        (e.prototype.ResetData = function () {
            r.default.instance.GameModel == r.GameModel.TimeLimit &&
                ((this.nowScoreList = []), (this.gameDatalist = null));
        }),
        (e.prototype.set_nowScoreList = function (e) {
            if (r.default.instance.GameModel == r.GameModel.TimeLimit) {
                for (var t = !0, o = 0; o < this.nowScoreList.length; o++) {
                    var n = this.nowScoreList[o];
                    n.snake_name == e.snakeName && ((n.score = e.score), (t = !1));
                }
                if (t) {
                    var i = new c();
                    (i.snake_name = e.snakeName), (i.score = e.score), this.nowScoreList.push(i);
                }
            }
        }),
        (e.prototype.set_oldScoreList = function (e) {
            if (r.default.instance.GameModel == r.GameModel.TimeLimit) {
                for (var t = !0, o = 0; o < this.nowScoreList.length; o++) {
                    var n = this.nowScoreList[o];
                    n.snake_name == e.snakeName && ((n.oldScore += e.score), (t = !1));
                }
                if (t) {
                    var i = new c();
                    (i.snake_name = e.snakeName), (i.oldScore += e.score), this.nowScoreList.push(i);
                }
            }
        }),
        (e.prototype.set_killData = function (e, t) {
            if (r.default.instance.GameModel == r.GameModel.TimeLimit) {
                for (var o = !0, n = 0; n < this.nowScoreList.length; n++) {
                    var i = this.nowScoreList[n];
                    i.snake_name == t.snakeName && ((i.killNum += 1), (i.killScore += e.score), (o = !1));
                }
                if (o) {
                    var a = new c();
                    (a.snake_name = t.snakeName), (a.killNum += 1), (a.killScore += e.score), this.nowScoreList.push(a);
                }
            }
        }),
        (e.prototype.getList1 = function () {
            this.cloneDataList();
            for (var e = this.gameDatalist, t = 0; t < e.length; t++)
                for (var o = t; o < e.length; o++)
                    if (e[t].score < e[o].score) {
                        var n = e[t];
                        (e[t] = e[o]), (e[o] = n);
                    }
            return e;
        }),
        (e.prototype.getList2 = function () {
            this.cloneDataList();
            for (var e = this.gameDatalist, t = 0; t < e.length; t++)
                for (var o = t; o < e.length; o++)
                    if (e[t].score + e[t].oldScore < e[o].score + e[o].oldScore) {
                        var n = e[t];
                        (e[t] = e[o]), (e[o] = n);
                    }
            return e;
        }),
        (e.prototype.getList3 = function () {
            this.cloneDataList();
            for (var e = this.gameDatalist, t = 0; t < e.length; t++)
                for (var o = t; o < e.length; o++)
                    if (e[t].killNum < e[o].killNum) {
                        var n = e[t];
                        (e[t] = e[o]), (e[o] = n);
                    }
            return e;
        }),
        (e.prototype.getList4 = function () {
            this.cloneDataList();
            for (var e = this.gameDatalist, t = 0; t < e.length; t++)
                for (var o = t; o < e.length; o++)
                    if (e[t].killScore < e[o].killScore) {
                        var n = e[t];
                        (e[t] = e[o]), (e[o] = n);
                    }
            return e;
        }),
        (e.prototype.cloneDataList = function () {
            if (!this.gameDatalist) {
                this.gameDatalist = JSON.parse(JSON.stringify(this.nowScoreList));
                for (var e = 0; e < this.gameDatalist.length; e++) {
                    var t = this.gameDatalist[e];
                    if (t.snake_name == r.default.instance.UserName)
                        t.randLevel = s.default.instance.getPlayerLevel().type;
                    else {
                        var o = Number(a.default.getItem("AIRandLevelScore" + t.snake_name, "1"));
                        1 == o &&
                            ((o = a.default.randomFrom(1, 800)),
                            a.default.setItem("AIRandLevelScore" + t.snake_name, o + ""));
                        for (var n = i.default.PlayerLevelData, c = void 0, l = 0; l < n.length; l++) {
                            var d = n[l];
                            o >= d.start_score && o <= d.end_score && (c = d.type);
                        }
                        c || (c = n[n.length - 1].type), (t.randLevel = c);
                    }
                }
            }
            return this.gameDatalist;
        }),
        (e._instance = null),
        e
    );
})();
n.default = l;
